let App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    size:10,
    refresh:false,
    down:false,
    allData:true,
    notData:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  getList(){
    let that = this
    let data = {
      page:that.data.page,
      pagesize:that.data.size
    }
    App._get(App.Domain+'Handler/Applet/getGarbageOrder', data, function (result) {
      if(result.code == 1){
        let processing = result.data.list
        if(processing.length<10){
         that.setData({
            allData:false,
            notData:true
         })
        }
        processing.forEach(item=>{
          item.mobile = item.mobile.substring(0, 3) + '****' + item.mobile.substring(7); 
        })
        if(that.data.page == 1){
          that.setData({
            orderList: processing
          })
        }else{
          that.setData({
            orderList:that.data.orderList.concat(result.data.list)
          })
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  //查看订单
  lookOrder(e){
    let id = e.currentTarget.dataset.id
    wx.redirectTo({
      url: '../order/index?id='+id
    })
  },
  //抢单
  getOrders(e){ 
    let id = e.currentTarget.dataset.id
    App._post(App.Domain+'Handler/Applet/takeSeaOrderToMind', {order_id :id}, function (result) {
      if(result.code == 1){
        wx.showModal({
          title: '提示',
          content: '抢单成功',
          success (res) {
            if (res.confirm) {
              console.log('用户点击确定')
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }else{
        wx.showToast({
          title: result.data.info,
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
//下拉刷新
onPullDownRefresh() {
  this.setData({refresh:true,allData:true,page:1,notData:false})
  this.getList()
  wx.showNavigationBarLoading() 
  setTimeout(()=>{
    this.getData = '数据拿到了'
    this.setData({refresh:false})
    wx.stopPullDownRefresh()
    wx.hideNavigationBarLoading()
  },1000)
},
//触底加载
onReachBottom:function(options){
   let that =  this
  if(!this.data.allData){
    return
  }else{
    this.setData({
      down:true
    })
    let page = that.data.page
    page++
    this.setData({page:page})
    setTimeout(()=>{
      that.getList()
      this.getData = '数据拿到了'
      this.setData({down:false})
      wx.stopPullDownRefresh()
      wx.hideNavigationBarLoading()
    },1000)
  }
},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})